--
-- PostgreSQL database dump
--

-- Dumped from database version 9.3.4
-- Dumped by pg_dump version 9.3.4
-- Started on 2014-06-15 22:44:43

SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;

--
-- TOC entry 8 (class 2615 OID 24743)
-- Name: leilao; Type: SCHEMA; Schema: -; Owner: postgres
--

CREATE SCHEMA leilao;


ALTER SCHEMA leilao OWNER TO postgres;

SET search_path = leilao, pg_catalog;

--
-- TOC entry 201 (class 1255 OID 41356)
-- Name: garatirUmGanhadorPorLeilao(); Type: FUNCTION; Schema: leilao; Owner: postgres
--

CREATE FUNCTION "garatirUmGanhadorPorLeilao"() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
	idA INTEGER;
	qtdGanhLeilao INTEGER;
BEGIN
  idA := (SELECT ln.leilao_fk FROM leilao.t_lance ln WHERE ln.id = NEW.lance_fk);
  qtdGanhLeilao := (SELECT COUNT(*) FROM leilao.t_ganhador g INNER JOIN leilao.t_lance ln ON g.lance_fk = ln.id WHERE ln.leilao_fk = idA);
  IF (qtdGanhLeilao > 0 AND (TG_OP = 'INSERT')) THEN
  	RAISE EXCEPTION 'Não é permitido ter mais de um ganhador por leilão';
  END IF;
  idA := (SELECT ln.usuario_fk FROM leilao.t_lance ln WHERE ln.id = NEW.lance_fk);
  qtdGanhLeilao := (SELECT COUNT(*) FROM leilao.t_ganhador g INNER JOIN leilao.t_lance ln ON g.lance_fk = ln.id WHERE ln.usuario_fk = idA);
  IF (qtdGanhLeilao > 0 AND (TG_OP = 'INSERT')) THEN
  	RAISE EXCEPTION 'Não é permitido que um usuário ganhe mais de um leilão';
  END IF;
  RETURN NEW;
END;
$$;


ALTER FUNCTION leilao."garatirUmGanhadorPorLeilao"() OWNER TO postgres;

--
-- TOC entry 199 (class 1255 OID 41349)
-- Name: impedirAlterLeilaoComLances(); Type: FUNCTION; Schema: leilao; Owner: postgres
--

CREATE FUNCTION "impedirAlterLeilaoComLances"() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
	idA INTEGER;
	qtdLances INTEGER;
BEGIN
  IF (TG_OP = 'UPDATE') THEN
    idA := NEW.id;
  ELSIF (TG_OP = 'DELETE') THEN
    idA := OLD.id;
  END IF;
  qtdLances := (SELECT COUNT(*) FROM leilao.t_lance ln WHERE ln.leilao_fk = idA);
  IF (qtdLances > 0) THEN
  	RAISE EXCEPTION 'Não é permitido atualizar\deletar leilões com lances';
  END IF;
  RETURN NEW;
END;
$$;


ALTER FUNCTION leilao."impedirAlterLeilaoComLances"() OWNER TO postgres;

--
-- TOC entry 200 (class 1255 OID 41358)
-- Name: validarLance(); Type: FUNCTION; Schema: leilao; Owner: postgres
--

CREATE FUNCTION "validarLance"() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
	incr DOUBLE PRECISION;
	vlrLanceAtual DOUBLE PRECISION;
	vlrLanceMin DOUBLE PRECISION;
	duracao INTEGER;
	horaUltLance TIMESTAMP;
	tempoInicial TIMESTAMP;
	tempoFinal TIMESTAMP;
BEGIN
  IF (TG_OP = 'UPDATE' OR TG_OP = 'DELETE') THEN
  	RAISE EXCEPTION 'Não é permitido atualizar\deletar lances';
  ELSIF (TG_OP = 'INSERT') THEN
    SELECT vlr_lance_min, vlr_inc_lance, tempo_duracao, data_inicio INTO vlrLanceMin, incr, duracao, tempoInicial FROM leilao.t_leilao WHERE id = NEW.leilao_fk;
    SELECT MAX(ln.vlr_lance), ln.hora_lance INTO vlrLanceAtual, horaUltLance FROM leilao.t_lance ln WHERE ln.leilao_fk = NEW.leilao_fk GROUP BY ln.hora_lance;
    IF (NEW.vlr_lance <> vlrLanceAtual + incr) THEN
	RAISE EXCEPTION 'O valor do lance é inválido';
    END IF;
    NEW.hora_lance := NOW();
    IF (NEW.hora_lance < tempoInicial) THEN
    	RAISE EXCEPTION 'Não é permitido ofertar lances, pois o leilão ainda não começou';
    END IF;
    tempoFinal := (SELECT (horaUltLance + (duracao || ' seconds')::interval));
    IF (NEW.hora_lance > tempoFinal) THEN
    	RAISE EXCEPTION 'Não é permitido ofertar lances, pois o leilão está encerrado';
    END IF;
    RETURN NEW;
  END IF;
END;
$$;


ALTER FUNCTION leilao."validarLance"() OWNER TO postgres;

--
-- TOC entry 184 (class 1259 OID 24883)
-- Name: seq_empresa; Type: SEQUENCE; Schema: leilao; Owner: postgres
--

CREATE SEQUENCE seq_empresa
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE leilao.seq_empresa OWNER TO postgres;

--
-- TOC entry 178 (class 1259 OID 24756)
-- Name: seq_ganhador; Type: SEQUENCE; Schema: leilao; Owner: postgres
--

CREATE SEQUENCE seq_ganhador
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE leilao.seq_ganhador OWNER TO postgres;

--
-- TOC entry 177 (class 1259 OID 24754)
-- Name: seq_lance; Type: SEQUENCE; Schema: leilao; Owner: postgres
--

CREATE SEQUENCE seq_lance
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE leilao.seq_lance OWNER TO postgres;

--
-- TOC entry 176 (class 1259 OID 24752)
-- Name: seq_leilao; Type: SEQUENCE; Schema: leilao; Owner: postgres
--

CREATE SEQUENCE seq_leilao
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE leilao.seq_leilao OWNER TO postgres;

--
-- TOC entry 174 (class 1259 OID 24744)
-- Name: seq_produto; Type: SEQUENCE; Schema: leilao; Owner: postgres
--

CREATE SEQUENCE seq_produto
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE leilao.seq_produto OWNER TO postgres;

--
-- TOC entry 175 (class 1259 OID 24750)
-- Name: seq_usuario; Type: SEQUENCE; Schema: leilao; Owner: postgres
--

CREATE SEQUENCE seq_usuario
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE leilao.seq_usuario OWNER TO postgres;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- TOC entry 185 (class 1259 OID 24885)
-- Name: t_empresa; Type: TABLE; Schema: leilao; Owner: postgres; Tablespace: 
--

CREATE TABLE t_empresa (
    id integer DEFAULT nextval('seq_empresa'::regclass) NOT NULL,
    nome character varying(20) NOT NULL,
    dominio character varying(20) NOT NULL
);
ALTER TABLE ONLY t_empresa ALTER COLUMN id SET STATISTICS 0;
ALTER TABLE ONLY t_empresa ALTER COLUMN nome SET STATISTICS 0;
ALTER TABLE ONLY t_empresa ALTER COLUMN dominio SET STATISTICS 0;


ALTER TABLE leilao.t_empresa OWNER TO postgres;

--
-- TOC entry 183 (class 1259 OID 24820)
-- Name: t_ganhador; Type: TABLE; Schema: leilao; Owner: postgres; Tablespace: 
--

CREATE TABLE t_ganhador (
    id integer DEFAULT nextval('seq_ganhador'::regclass) NOT NULL,
    qtd_produto integer DEFAULT 1,
    lance_fk integer NOT NULL
);
ALTER TABLE ONLY t_ganhador ALTER COLUMN id SET STATISTICS 0;


ALTER TABLE leilao.t_ganhador OWNER TO postgres;

--
-- TOC entry 182 (class 1259 OID 24803)
-- Name: t_lance; Type: TABLE; Schema: leilao; Owner: postgres; Tablespace: 
--

CREATE TABLE t_lance (
    id integer DEFAULT nextval('seq_lance'::regclass) NOT NULL,
    usuario_fk integer NOT NULL,
    leilao_fk integer NOT NULL,
    vlr_lance double precision NOT NULL,
    hora_lance timestamp without time zone DEFAULT now() NOT NULL
);
ALTER TABLE ONLY t_lance ALTER COLUMN id SET STATISTICS 0;
ALTER TABLE ONLY t_lance ALTER COLUMN usuario_fk SET STATISTICS 0;
ALTER TABLE ONLY t_lance ALTER COLUMN leilao_fk SET STATISTICS 0;
ALTER TABLE ONLY t_lance ALTER COLUMN hora_lance SET STATISTICS 0;


ALTER TABLE leilao.t_lance OWNER TO postgres;

--
-- TOC entry 181 (class 1259 OID 24779)
-- Name: t_leilao; Type: TABLE; Schema: leilao; Owner: postgres; Tablespace: 
--

CREATE TABLE t_leilao (
    id integer DEFAULT nextval('seq_leilao'::regclass) NOT NULL,
    produto_fk integer NOT NULL,
    qtd_max_produto integer DEFAULT 2,
    vlr_lance_min double precision DEFAULT 50,
    vlr_inc_lance double precision DEFAULT 5,
    data_inicio timestamp without time zone NOT NULL,
    tempo_max_select_qtd integer DEFAULT 30,
    tempo_duracao integer DEFAULT 2
);


ALTER TABLE leilao.t_leilao OWNER TO postgres;

--
-- TOC entry 2047 (class 0 OID 0)
-- Dependencies: 181
-- Name: COLUMN t_leilao.qtd_max_produto; Type: COMMENT; Schema: leilao; Owner: postgres
--

COMMENT ON COLUMN t_leilao.qtd_max_produto IS 'Quantidade máxima estabelecida para arremate.';


--
-- TOC entry 2048 (class 0 OID 0)
-- Dependencies: 181
-- Name: COLUMN t_leilao.tempo_max_select_qtd; Type: COMMENT; Schema: leilao; Owner: postgres
--

COMMENT ON COLUMN t_leilao.tempo_max_select_qtd IS 'Tempo máximo para escolha da quantidade de produtos arrematados.';


--
-- TOC entry 179 (class 1259 OID 24758)
-- Name: t_produto; Type: TABLE; Schema: leilao; Owner: postgres; Tablespace: 
--

CREATE TABLE t_produto (
    id integer DEFAULT nextval('seq_produto'::regclass) NOT NULL,
    nome character varying(20) NOT NULL,
    descricao character varying(120) NOT NULL,
    qtd_total integer NOT NULL,
    vlr double precision DEFAULT 0 NOT NULL,
    foto text
);
ALTER TABLE ONLY t_produto ALTER COLUMN id SET STATISTICS 0;
ALTER TABLE ONLY t_produto ALTER COLUMN nome SET STATISTICS 0;
ALTER TABLE ONLY t_produto ALTER COLUMN descricao SET STATISTICS 0;
ALTER TABLE ONLY t_produto ALTER COLUMN qtd_total SET STATISTICS 0;


ALTER TABLE leilao.t_produto OWNER TO postgres;

--
-- TOC entry 180 (class 1259 OID 24764)
-- Name: t_usuario; Type: TABLE; Schema: leilao; Owner: postgres; Tablespace: 
--

CREATE TABLE t_usuario (
    id integer DEFAULT nextval('seq_usuario'::regclass) NOT NULL,
    nome character varying(80) NOT NULL,
    email character varying(80) NOT NULL,
    senha character varying(60) NOT NULL,
    nm_setor character varying(40) NOT NULL,
    empresa_fk integer NOT NULL,
    permissoes character varying(40) DEFAULT 'ROLE_FUNCIONARIO'::character varying,
    status character(1) DEFAULT 'I'::bpchar
);
ALTER TABLE ONLY t_usuario ALTER COLUMN id SET STATISTICS 0;
ALTER TABLE ONLY t_usuario ALTER COLUMN email SET STATISTICS 0;


ALTER TABLE leilao.t_usuario OWNER TO postgres;

--
-- TOC entry 2052 (class 0 OID 0)
-- Dependencies: 184
-- Name: seq_empresa; Type: SEQUENCE SET; Schema: leilao; Owner: postgres
--

SELECT pg_catalog.setval('seq_empresa', 12, true);


--
-- TOC entry 2053 (class 0 OID 0)
-- Dependencies: 178
-- Name: seq_ganhador; Type: SEQUENCE SET; Schema: leilao; Owner: postgres
--

SELECT pg_catalog.setval('seq_ganhador', 2, true);


--
-- TOC entry 2054 (class 0 OID 0)
-- Dependencies: 177
-- Name: seq_lance; Type: SEQUENCE SET; Schema: leilao; Owner: postgres
--

SELECT pg_catalog.setval('seq_lance', 296, true);


--
-- TOC entry 2055 (class 0 OID 0)
-- Dependencies: 176
-- Name: seq_leilao; Type: SEQUENCE SET; Schema: leilao; Owner: postgres
--

SELECT pg_catalog.setval('seq_leilao', 4, true);


--
-- TOC entry 2056 (class 0 OID 0)
-- Dependencies: 174
-- Name: seq_produto; Type: SEQUENCE SET; Schema: leilao; Owner: postgres
--

SELECT pg_catalog.setval('seq_produto', 4, true);


--
-- TOC entry 2057 (class 0 OID 0)
-- Dependencies: 175
-- Name: seq_usuario; Type: SEQUENCE SET; Schema: leilao; Owner: postgres
--

SELECT pg_catalog.setval('seq_usuario', 37, true);


--
-- TOC entry 2029 (class 0 OID 24885)
-- Dependencies: 185
-- Data for Name: t_empresa; Type: TABLE DATA; Schema: leilao; Owner: postgres
--

INSERT INTO t_empresa (id, nome, dominio) VALUES (2, 'Kompax', 'kompax.com.br');
INSERT INTO t_empresa (id, nome, dominio) VALUES (1, 'VTI', 'VTI.COM.BR');


--
-- TOC entry 2027 (class 0 OID 24820)
-- Dependencies: 183
-- Data for Name: t_ganhador; Type: TABLE DATA; Schema: leilao; Owner: postgres
--

INSERT INTO t_ganhador (id, qtd_produto, lance_fk) VALUES (1, 1, 291);
INSERT INTO t_ganhador (id, qtd_produto, lance_fk) VALUES (2, 2, 294);


--
-- TOC entry 2026 (class 0 OID 24803)
-- Dependencies: 182
-- Data for Name: t_lance; Type: TABLE DATA; Schema: leilao; Owner: postgres
--

INSERT INTO t_lance (id, usuario_fk, leilao_fk, vlr_lance, hora_lance) VALUES (291, 36, 3, 25, '2014-06-15 19:37:39.894');
INSERT INTO t_lance (id, usuario_fk, leilao_fk, vlr_lance, hora_lance) VALUES (293, 36, 4, 25, '2014-06-15 21:40:28.511');
INSERT INTO t_lance (id, usuario_fk, leilao_fk, vlr_lance, hora_lance) VALUES (294, 1, 4, 26, '2014-06-15 21:40:47.15');


--
-- TOC entry 2025 (class 0 OID 24779)
-- Dependencies: 181
-- Data for Name: t_leilao; Type: TABLE DATA; Schema: leilao; Owner: postgres
--

INSERT INTO t_leilao (id, produto_fk, qtd_max_produto, vlr_lance_min, vlr_inc_lance, data_inicio, tempo_max_select_qtd, tempo_duracao) VALUES (3, 1, 2, 25, 1, '2014-06-14 23:30:00', 30, 30);
INSERT INTO t_leilao (id, produto_fk, qtd_max_produto, vlr_lance_min, vlr_inc_lance, data_inicio, tempo_max_select_qtd, tempo_duracao) VALUES (4, 1, 2, 25, 1, '2014-06-15 21:30:00', 30, 30);


--
-- TOC entry 2023 (class 0 OID 24758)
-- Dependencies: 179
-- Data for Name: t_produto; Type: TABLE DATA; Schema: leilao; Owner: postgres
--

INSERT INTO t_produto (id, nome, descricao, qtd_total, vlr, foto) VALUES (1, 'Ingresso copa', 'Ingresso copa', 20, 0, NULL);


--
-- TOC entry 2024 (class 0 OID 24764)
-- Dependencies: 180
-- Data for Name: t_usuario; Type: TABLE DATA; Schema: leilao; Owner: postgres
--

INSERT INTO t_usuario (id, nome, email, senha, nm_setor, empresa_fk, permissoes, status) VALUES (36, 'EDNARDO MATOS', 'EDNARDOMATOS', '202cb962ac59075b964b07152d234b70', 'CDS', 1, 'ROLE_FUNCIONARIO', 'A');
INSERT INTO t_usuario (id, nome, email, senha, nm_setor, empresa_fk, permissoes, status) VALUES (37, 'TESTE', 'TESTE', '202cb962ac59075b964b07152d234b70', 'CDS', 1, 'ROLE_FUNCIONARIO', 'A');
INSERT INTO t_usuario (id, nome, email, senha, nm_setor, empresa_fk, permissoes, status) VALUES (1, 'ADMIN', 'ADMIN', '202cb962ac59075b964b07152d234b70', 'CDS', 1, 'ROLE_ADMIN', 'A');


--
-- TOC entry 1898 (class 2606 OID 24894)
-- Name: t_empresa_dominio_key; Type: CONSTRAINT; Schema: leilao; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY t_empresa
    ADD CONSTRAINT t_empresa_dominio_key UNIQUE (dominio);


--
-- TOC entry 1900 (class 2606 OID 24892)
-- Name: t_empresa_nome_key; Type: CONSTRAINT; Schema: leilao; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY t_empresa
    ADD CONSTRAINT t_empresa_nome_key UNIQUE (nome);


--
-- TOC entry 1902 (class 2606 OID 24890)
-- Name: t_empresa_pkey; Type: CONSTRAINT; Schema: leilao; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY t_empresa
    ADD CONSTRAINT t_empresa_pkey PRIMARY KEY (id);


--
-- TOC entry 1896 (class 2606 OID 24826)
-- Name: t_ganhador_pkey; Type: CONSTRAINT; Schema: leilao; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY t_ganhador
    ADD CONSTRAINT t_ganhador_pkey PRIMARY KEY (id);


--
-- TOC entry 1892 (class 2606 OID 33158)
-- Name: t_lance_leilao_vlr_key; Type: CONSTRAINT; Schema: leilao; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY t_lance
    ADD CONSTRAINT t_lance_leilao_vlr_key UNIQUE (leilao_fk, vlr_lance);


--
-- TOC entry 1894 (class 2606 OID 24809)
-- Name: t_lance_pkey; Type: CONSTRAINT; Schema: leilao; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY t_lance
    ADD CONSTRAINT t_lance_pkey PRIMARY KEY (id);


--
-- TOC entry 1890 (class 2606 OID 24787)
-- Name: t_leilao_pkey; Type: CONSTRAINT; Schema: leilao; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY t_leilao
    ADD CONSTRAINT t_leilao_pkey PRIMARY KEY (id);


--
-- TOC entry 1882 (class 2606 OID 24868)
-- Name: t_produto_nome_key; Type: CONSTRAINT; Schema: leilao; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY t_produto
    ADD CONSTRAINT t_produto_nome_key UNIQUE (nome);


--
-- TOC entry 1884 (class 2606 OID 24763)
-- Name: t_produto_pkey; Type: CONSTRAINT; Schema: leilao; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY t_produto
    ADD CONSTRAINT t_produto_pkey PRIMARY KEY (id);


--
-- TOC entry 1886 (class 2606 OID 33156)
-- Name: t_usuario_email_key; Type: CONSTRAINT; Schema: leilao; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY t_usuario
    ADD CONSTRAINT t_usuario_email_key UNIQUE (email);


--
-- TOC entry 1888 (class 2606 OID 24769)
-- Name: t_usuario_pkey; Type: CONSTRAINT; Schema: leilao; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY t_usuario
    ADD CONSTRAINT t_usuario_pkey PRIMARY KEY (id);


--
-- TOC entry 1910 (class 2620 OID 41357)
-- Name: t_ganhador_tgr; Type: TRIGGER; Schema: leilao; Owner: postgres
--

CREATE TRIGGER t_ganhador_tgr BEFORE INSERT OR UPDATE ON t_ganhador FOR EACH ROW EXECUTE PROCEDURE "garatirUmGanhadorPorLeilao"();


--
-- TOC entry 1909 (class 2620 OID 41360)
-- Name: t_lance_tgr; Type: TRIGGER; Schema: leilao; Owner: postgres
--

CREATE TRIGGER t_lance_tgr BEFORE INSERT OR DELETE OR UPDATE ON t_lance FOR EACH ROW EXECUTE PROCEDURE "validarLance"();


--
-- TOC entry 1908 (class 2620 OID 41359)
-- Name: t_leilao_tgr; Type: TRIGGER; Schema: leilao; Owner: postgres
--

CREATE TRIGGER t_leilao_tgr BEFORE INSERT OR DELETE OR UPDATE ON t_leilao FOR EACH ROW EXECUTE PROCEDURE "impedirAlterLeilaoComLances"();


--
-- TOC entry 1907 (class 2606 OID 41351)
-- Name: t_ganhador_lance_fk; Type: FK CONSTRAINT; Schema: leilao; Owner: postgres
--

ALTER TABLE ONLY t_ganhador
    ADD CONSTRAINT t_ganhador_lance_fk FOREIGN KEY (lance_fk) REFERENCES t_lance(id);


--
-- TOC entry 1906 (class 2606 OID 24815)
-- Name: t_lance_leilao_fk; Type: FK CONSTRAINT; Schema: leilao; Owner: postgres
--

ALTER TABLE ONLY t_lance
    ADD CONSTRAINT t_lance_leilao_fk FOREIGN KEY (leilao_fk) REFERENCES t_leilao(id);


--
-- TOC entry 1905 (class 2606 OID 24810)
-- Name: t_lance_usuario_fk; Type: FK CONSTRAINT; Schema: leilao; Owner: postgres
--

ALTER TABLE ONLY t_lance
    ADD CONSTRAINT t_lance_usuario_fk FOREIGN KEY (usuario_fk) REFERENCES t_usuario(id);


--
-- TOC entry 1904 (class 2606 OID 24793)
-- Name: t_leilao_produto_fk; Type: FK CONSTRAINT; Schema: leilao; Owner: postgres
--

ALTER TABLE ONLY t_leilao
    ADD CONSTRAINT t_leilao_produto_fk FOREIGN KEY (produto_fk) REFERENCES t_produto(id);


--
-- TOC entry 1903 (class 2606 OID 24901)
-- Name: t_usuario_empresa_fk; Type: FK CONSTRAINT; Schema: leilao; Owner: postgres
--

ALTER TABLE ONLY t_usuario
    ADD CONSTRAINT t_usuario_empresa_fk FOREIGN KEY (empresa_fk) REFERENCES t_empresa(id);


--
-- TOC entry 2034 (class 0 OID 0)
-- Dependencies: 8
-- Name: leilao; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA leilao FROM PUBLIC;
REVOKE ALL ON SCHEMA leilao FROM postgres;
GRANT ALL ON SCHEMA leilao TO postgres;
GRANT USAGE ON SCHEMA leilao TO leilao;


--
-- TOC entry 2035 (class 0 OID 0)
-- Dependencies: 201
-- Name: garatirUmGanhadorPorLeilao(); Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON FUNCTION "garatirUmGanhadorPorLeilao"() FROM PUBLIC;
REVOKE ALL ON FUNCTION "garatirUmGanhadorPorLeilao"() FROM postgres;
GRANT ALL ON FUNCTION "garatirUmGanhadorPorLeilao"() TO postgres;
GRANT ALL ON FUNCTION "garatirUmGanhadorPorLeilao"() TO PUBLIC;
GRANT ALL ON FUNCTION "garatirUmGanhadorPorLeilao"() TO leilao;


--
-- TOC entry 2036 (class 0 OID 0)
-- Dependencies: 199
-- Name: impedirAlterLeilaoComLances(); Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON FUNCTION "impedirAlterLeilaoComLances"() FROM PUBLIC;
REVOKE ALL ON FUNCTION "impedirAlterLeilaoComLances"() FROM postgres;
GRANT ALL ON FUNCTION "impedirAlterLeilaoComLances"() TO postgres;
GRANT ALL ON FUNCTION "impedirAlterLeilaoComLances"() TO PUBLIC;
GRANT ALL ON FUNCTION "impedirAlterLeilaoComLances"() TO leilao;


--
-- TOC entry 2037 (class 0 OID 0)
-- Dependencies: 200
-- Name: validarLance(); Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON FUNCTION "validarLance"() FROM PUBLIC;
REVOKE ALL ON FUNCTION "validarLance"() FROM postgres;
GRANT ALL ON FUNCTION "validarLance"() TO postgres;
GRANT ALL ON FUNCTION "validarLance"() TO PUBLIC;
GRANT ALL ON FUNCTION "validarLance"() TO leilao;


--
-- TOC entry 2038 (class 0 OID 0)
-- Dependencies: 184
-- Name: seq_empresa; Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON SEQUENCE seq_empresa FROM PUBLIC;
REVOKE ALL ON SEQUENCE seq_empresa FROM postgres;
GRANT ALL ON SEQUENCE seq_empresa TO postgres;
GRANT ALL ON SEQUENCE seq_empresa TO leilao;


--
-- TOC entry 2039 (class 0 OID 0)
-- Dependencies: 178
-- Name: seq_ganhador; Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON SEQUENCE seq_ganhador FROM PUBLIC;
REVOKE ALL ON SEQUENCE seq_ganhador FROM postgres;
GRANT ALL ON SEQUENCE seq_ganhador TO postgres;
GRANT ALL ON SEQUENCE seq_ganhador TO leilao;


--
-- TOC entry 2040 (class 0 OID 0)
-- Dependencies: 177
-- Name: seq_lance; Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON SEQUENCE seq_lance FROM PUBLIC;
REVOKE ALL ON SEQUENCE seq_lance FROM postgres;
GRANT ALL ON SEQUENCE seq_lance TO postgres;
GRANT ALL ON SEQUENCE seq_lance TO leilao;


--
-- TOC entry 2041 (class 0 OID 0)
-- Dependencies: 176
-- Name: seq_leilao; Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON SEQUENCE seq_leilao FROM PUBLIC;
REVOKE ALL ON SEQUENCE seq_leilao FROM postgres;
GRANT ALL ON SEQUENCE seq_leilao TO postgres;
GRANT ALL ON SEQUENCE seq_leilao TO leilao;


--
-- TOC entry 2042 (class 0 OID 0)
-- Dependencies: 174
-- Name: seq_produto; Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON SEQUENCE seq_produto FROM PUBLIC;
REVOKE ALL ON SEQUENCE seq_produto FROM postgres;
GRANT ALL ON SEQUENCE seq_produto TO postgres;
GRANT ALL ON SEQUENCE seq_produto TO leilao;


--
-- TOC entry 2043 (class 0 OID 0)
-- Dependencies: 175
-- Name: seq_usuario; Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON SEQUENCE seq_usuario FROM PUBLIC;
REVOKE ALL ON SEQUENCE seq_usuario FROM postgres;
GRANT ALL ON SEQUENCE seq_usuario TO postgres;
GRANT ALL ON SEQUENCE seq_usuario TO leilao;


--
-- TOC entry 2044 (class 0 OID 0)
-- Dependencies: 185
-- Name: t_empresa; Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON TABLE t_empresa FROM PUBLIC;
REVOKE ALL ON TABLE t_empresa FROM postgres;
GRANT ALL ON TABLE t_empresa TO postgres;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE t_empresa TO leilao;


--
-- TOC entry 2045 (class 0 OID 0)
-- Dependencies: 183
-- Name: t_ganhador; Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON TABLE t_ganhador FROM PUBLIC;
REVOKE ALL ON TABLE t_ganhador FROM postgres;
GRANT ALL ON TABLE t_ganhador TO postgres;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE t_ganhador TO leilao;


--
-- TOC entry 2046 (class 0 OID 0)
-- Dependencies: 182
-- Name: t_lance; Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON TABLE t_lance FROM PUBLIC;
REVOKE ALL ON TABLE t_lance FROM postgres;
GRANT ALL ON TABLE t_lance TO postgres;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE t_lance TO leilao;


--
-- TOC entry 2049 (class 0 OID 0)
-- Dependencies: 181
-- Name: t_leilao; Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON TABLE t_leilao FROM PUBLIC;
REVOKE ALL ON TABLE t_leilao FROM postgres;
GRANT ALL ON TABLE t_leilao TO postgres;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE t_leilao TO leilao;


--
-- TOC entry 2050 (class 0 OID 0)
-- Dependencies: 179
-- Name: t_produto; Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON TABLE t_produto FROM PUBLIC;
REVOKE ALL ON TABLE t_produto FROM postgres;
GRANT ALL ON TABLE t_produto TO postgres;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE t_produto TO leilao;


--
-- TOC entry 2051 (class 0 OID 0)
-- Dependencies: 180
-- Name: t_usuario; Type: ACL; Schema: leilao; Owner: postgres
--

REVOKE ALL ON TABLE t_usuario FROM PUBLIC;
REVOKE ALL ON TABLE t_usuario FROM postgres;
GRANT ALL ON TABLE t_usuario TO postgres;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE t_usuario TO leilao;


-- Completed on 2014-06-15 22:44:44

--
-- PostgreSQL database dump complete
--

